package lab.gene.service.impl;

import java.util.List;
import java.util.Date;

import lab.gene.pojo.GeneImageFile;
import lab.gene.pojo.Gene;
import lab.user.pojo.User;
import lab.gene.service.GeneImageFileService;
import lab.gene.dao.GeneImageFileDAO;
import lab.gene.dao.GeneDAO;
import lab.user.dao.UserDAO;

public class GeneImageFileServiceImpl implements GeneImageFileService {

	@Override
	public void addGeneImageFile(String geneName, String userName, String formName, String fileName) {
		// TODO Auto-generated method stub
		GeneImageFileDAO dao = new GeneImageFileDAO();
		GeneDAO gdao = new GeneDAO();
		UserDAO udao = new UserDAO();
		Gene gene = gdao.getGene(geneName);
		User user = udao.getUser(userName);
		
		GeneImageFile file = new GeneImageFile();
		file.setDateModified(new Date());
		file.setFileName(fileName);
		file.setFormName(formName);
		file.setGene(gene);
		file.setOptMode("Add");
		file.setUser(user);
		dao.addGeneImageFile(file);
	}

	@Override
	public List<GeneImageFile> getGeneImageFilesByGeneNameAndFormName(
			String geneName, String formName) {
		// TODO Auto-generated method stub
		GeneImageFileDAO dao = new GeneImageFileDAO();
		GeneDAO gdao = new GeneDAO();
		Gene gene = gdao.getGene(geneName);
		return dao.getGeneImageFilesByGeneNameAndFormName(gene, formName);
	}
	
	@Override
	public List<GeneImageFile> getAllGeneImageFilesByGeneName(String geneName) {
		GeneImageFileDAO dao = new GeneImageFileDAO();
		GeneDAO gdao = new GeneDAO();
		Gene gene = gdao.getGene(geneName);
		return dao.getAllGeneImageFilesByGeneName(gene);
	}

	@Override
	public List<GeneImageFile> getGeneImageFilesByFileName(String fileName) {
		// TODO Auto-generated method stub
		GeneImageFileDAO dao = new GeneImageFileDAO();
		return dao.getGeneImageFilesByFileName(fileName);
	}

	@Override
	public GeneImageFile getGeneImageFilesById(Integer id) {
		// TODO Auto-generated method stub
		GeneImageFileDAO dao = new GeneImageFileDAO();
		return dao.getGeneImageFilesById(id);
	}

	@Override
	public void deleteGeneImageFiles(Integer id, String userName) {
		// TODO Auto-generated method stub
		GeneImageFileDAO dao = new GeneImageFileDAO();
		UserDAO udao = new UserDAO();
		User user = udao.getUser(userName);
		GeneImageFile f = dao.getGeneImageFilesById(id);
		f.setDateModified(new Date());
		f.setUser(user);
		f.setOptMode("Del");
		dao.addGeneImageFile(f);
	}
	

}
